home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / CHIP 2005-06.iso / program / grafik / myriad.exe / Disk1 / data1.cab / Intgclt_-_xref / xref.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-05-12  |  5.0 KB  |  186 lines

  1. // xref.cpp : Defines the initialization routines for the DLL.
  2. //
  3. #include "stdafx.h"
  4. #include <io.h>
  5. #include "xref.h"
  6.  
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12.  
  13.  
  14. //
  15. //    Note!
  16. //
  17. //        If this DLL is dynamically linked against the MFC
  18. //        DLLs, any functions exported from this DLL which
  19. //        call into MFC must have the AFX_MANAGE_STATE macro
  20. //        added at the very beginning of the function.
  21. //
  22. //        For example:
  23. //
  24. //        extern "C" BOOL PASCAL EXPORT ExportedFunction()
  25. //        {
  26. //            AFX_MANAGE_STATE(AfxGetStaticModuleState());
  27. //            // normal function body here
  28. //        }
  29. //
  30. //        It is very important that this macro appear in each
  31. //        function, prior to any calls into MFC.  This means that
  32. //        it must appear as the first statement within the 
  33. //        function, even before any object variable declarations
  34. //        as their constructors may generate calls into the MFC
  35. //        DLL.
  36. //
  37. //        Please see MFC Technical Notes 33 and 58 for additional
  38. //        details.
  39. //
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CXrefApp
  43.  
  44. BEGIN_MESSAGE_MAP(CXrefApp, CWinApp)
  45.     //{{AFX_MSG_MAP(CXrefApp)
  46.         // NOTE - the ClassWizard will add and remove mapping macros here.
  47.         //    DO NOT EDIT what you see in these blocks of generated code!
  48.     //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50.  
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CXrefApp construction
  53.  
  54. CXrefApp::CXrefApp()
  55. {
  56.     // TODO: add construction code here,
  57.     // Place all significant initialization in InitInstance
  58. }
  59.  
  60. /////////////////////////////////////////////////////////////////////////////
  61. // The one and only CXrefApp object
  62.  
  63. CXrefApp theApp;
  64.  
  65. /*
  66.  This is provided in case you need to do some initialization.
  67. It will be called when Myriad starts up.
  68.  
  69. return TRUE if you startup successfully.
  70. returning FALSE will cause Myriad to unload your xref.dll
  71. and proceed without you.
  72. */
  73.  
  74. BOOL CXrefApp::Init(void)
  75. {
  76.    BOOL ret = FALSE;
  77.    char filename[MAX_PATH];
  78.  
  79.    // get filename for xref list
  80.    if( GetModuleFileName( m_hInstance, filename, MAX_PATH) > 0 )
  81.    {
  82.       char drive[_MAX_DRIVE];   
  83.       char dir[_MAX_DIR];
  84.       
  85.       _splitpath( filename, drive, dir, NULL, NULL);
  86.       _makepath( filename, drive, dir, "srchpath", "txt" );
  87.  
  88.       ret = LoadSearchPaths(filename);
  89.    }
  90.  
  91.    return ret;
  92. }
  93.  
  94. /*
  95. LocalFile   = Path and filename of the file wanting the xref.  
  96.             Ignore this parameter if the xref is an .ini 
  97.             file or a .dat file.  Those files have no parent file.
  98.             This string may be empty or garbage in those cases.
  99.             Myriad uses this function for more than just xrefs.
  100.             It gets called for ini files, library dat files and font files too.
  101.             You may want to ignore (return FALSE) if all you care 
  102.             about are externally refrenced dwg files and the xref does 
  103.             not end in a ".dwg" extension.
  104.  
  105. xref        = Externally refrenced file to find.  The exact string 
  106.             specified in the parent file, so it may be a full path, 
  107.             or just a filename.  May be any of the following types 
  108.             of files:  .ini, .dat, .dwg, .shx and .ttf
  109.  
  110. Answer      = character buffer to write your answer to.  
  111.             Supply a full path to the file you want us to use.
  112.  
  113. Answersize  = size, in bytes, of the character buffer pointed to by Answer.
  114.  
  115. Return TRUE, if you want us to use the file you write to the Answer 
  116. buffer.  Otherwise, return FALSE and Myriad will search for the xref
  117. the way it normally does.
  118. */
  119. BOOL CXrefApp::GetXref(LPCSTR LocalFile, LPCSTR xref, char *Answer, int Answersize)
  120. {
  121.    BOOL ret = FALSE;   
  122.  
  123.    if(m_SearchPaths.GetCount())
  124.    {
  125.       CString buffer;
  126.       char filename[MAX_PATH];
  127.       char drive[_MAX_DRIVE];   
  128.       char dir[_MAX_DIR];
  129.       
  130.       POSITION currentpos = m_SearchPaths.GetHeadPosition();
  131.  
  132.       while(currentpos)
  133.       {
  134.          buffer = m_SearchPaths.GetNext( currentpos );
  135.          if(buffer.GetLength() > 0)
  136.          {
  137.             _splitpath( buffer, drive, dir, NULL, NULL);
  138.             _makepath( filename, drive, dir, xref, NULL);
  139.  
  140.             if(_access( filename, 04 ) != -1)
  141.             {
  142.                strncpy(Answer, filename, Answersize);
  143.                ret = TRUE;
  144.                break;
  145.             }
  146.          }
  147.       }      
  148.    }  
  149.  
  150.    return ret;
  151. }
  152.  
  153. /* 
  154. This is provided in case you need to clean up.
  155. It will be called when Myriad shuts down.
  156. */
  157.  
  158. void CXrefApp::DeInit(void)
  159. {
  160. }
  161.  
  162. BOOL CXrefApp::LoadSearchPaths(LPCSTR filename)
  163. {
  164.    BOOL ret = FALSE;   
  165.    
  166.    if(_access( filename, 04 ) != -1)
  167.    {
  168.       CString buffer;
  169.       CStdioFile listfile( filename, CFile::modeRead );
  170.  
  171.       while(listfile.ReadString(buffer))
  172.       {
  173.          if(buffer.GetLength() > 0 )
  174.          {
  175.             m_SearchPaths.AddTail(buffer);
  176.          }
  177.       }
  178.  
  179.       if(m_SearchPaths.GetCount())
  180.       {
  181.          ret = TRUE;
  182.       }
  183.    }
  184.  
  185.    return ret;
  186. }